package com.incrediblesoft.redjey.demo;

import com.incrediblesoft.redjey.Button;
import com.incrediblesoft.redjey.CustomImage;
import com.incrediblesoft.redjey.CustomFont;
import com.incrediblesoft.redjey.Dimension;
import com.incrediblesoft.redjey.CustomImage;

import javax.microedition.lcdui.Graphics;
import java.util.Hashtable;

public class CustomButton extends Button
{
    public CustomButton(String title)
    {
        super(title);
    }

    public CustomButton(String title, String styleClassName)
    {
        super(title, styleClassName);
    }

    public CustomButton(String title, CustomImage image)
    {
        super(title, image);
    }

    public CustomButton(String title, CustomImage image, String styleClassName)
    {
        super(title, image, styleClassName);
    }

    protected Dimension calcPreferredSize(int paddingHorizontal, int paddingVertical, CustomFont font, Hashtable attributes)
    {
        int dim_x = Math.max(text.length() > 0 ? font.stringWidth(text) : 0, (image != null ? image.getWidth() : 0));
        int dim_y = (image != null ? image.getHeight() + paddingVertical : 0) + font.getHeight();

        return new Dimension(dim_x, dim_y);
    }

    protected void paintComponent(Graphics g)
    {
        if (image != null)
        {
            image.paint(g, clientSize.width / 2, 0, Graphics.HCENTER | Graphics.TOP);
            g.translate(0, image.getHeight() + currentStyle.getPaddingVertical());
        }

        if (text.length() > 0)
        {
            currentStyle.getFont().drawString(g, text, clientSize.width / 2, 0, Graphics.HCENTER | Graphics.TOP);
        }

        //g.translate(-insets[0], -insets[2]);
    }

}
